#!/bin/bash

# 检查依赖库脚本
echo "=== Checking Dependencies ==="

# 检查Boost
echo -n "Boost: "
dpkg -l | grep libboost-dev | awk '{print $3}'

# 检查Protobuf
echo -n "Protobuf: "
dpkg -l | grep libprotobuf-dev | awk '{print $3}'

# 检查gRPC
echo -n "gRPC: "
dpkg -l | grep libgrpc++-dev | awk '{print $3}'

# 检查nlohmann-json
echo -n "nlohmann-json: "
dpkg -l | grep nlohmann-json3-dev | awk '{print $3}'

# 检查MySQL Connector
echo -n "MySQL Connector C++: "
dpkg -l | grep libmysqlcppconn-dev | awk '{print $3}'

# 检查Hiredis
echo -n "Hiredis: "
dpkg -l | grep libhiredis-dev | awk '{print $3}'

echo ""
echo "=== Missing Dependencies ==="

# 检查缺失的库
MISSING=""

if ! dpkg -l | grep -q libboost-all-dev; then
    echo "✗ libboost-all-dev"
    MISSING="$MISSING libboost-all-dev"
fi

if ! dpkg -l | grep -q libprotobuf-dev; then
    echo "✗ libprotobuf-dev protobuf-compiler"
    MISSING="$MISSING libprotobuf-dev protobuf-compiler"
fi

if ! dpkg -l | grep -q libgrpc++-dev; then
    echo "✗ libgrpc++-dev protobuf-compiler-grpc"
    MISSING="$MISSING libgrpc++-dev protobuf-compiler-grpc"
fi

if ! dpkg -l | grep -q nlohmann-json3-dev; then
    echo "✗ nlohmann-json3-dev"
    MISSING="$MISSING nlohmann-json3-dev"
fi

if ! dpkg -l | grep -q libmysqlcppconn-dev; then
    echo "✗ libmysqlcppconn-dev"
    MISSING="$MISSING libmysqlcppconn-dev"
fi

if ! dpkg -l | grep -q libhiredis-dev; then
    echo "✗ libhiredis-dev"
    MISSING="$MISSING libhiredis-dev"
fi

if [ -z "$MISSING" ]; then
    echo "✓ All dependencies installed!"
else
    echo ""
    echo "=== Install Missing Dependencies ==="
    echo "Run:"
    echo "sudo apt update"
    echo "sudo apt install -y$MISSING"
fi
